package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportSmsSendLog;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportSmsSendLogDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2019-05-18 20:14:30
 */
public class TransportSmsSendLogConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportSmsSendLogConverts.class);

    public static List<TransportSmsSendLogDTO> convert(List<TransportSmsSendLog> transportSmsSendLogList) {
        if (CollectionUtils.isEmpty(transportSmsSendLogList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportSmsSendLogDTO> transportSmsSendLogListResult = Lists.newArrayList();
        for (TransportSmsSendLog transportSmsSendLog : transportSmsSendLogList) {
            transportSmsSendLogListResult.add(convert(transportSmsSendLog));
        }
        return transportSmsSendLogListResult;
    }

    public static TransportSmsSendLogDTO convert(TransportSmsSendLog transportSmsSendLog) {
        try {
            return BeanUtils.copy(transportSmsSendLog, TransportSmsSendLogDTO.class);
        } catch (Exception e) {
            LOG.error("TransportSmsSendLog到TransportSmsSendLogDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportSmsSendLog到TransportSmsSendLogDTO转换失败", e);
        }
    }

    public static TransportSmsSendLog convert(TransportSmsSendLogDTO transportSmsSendLogDTO) {
        try {
            return BeanUtils.copy(transportSmsSendLogDTO, TransportSmsSendLog.class);
        } catch (Exception e) {
            LOG.error("TransportSmsSendLogDTO到TransportSmsSendLog转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportSmsSendLogDTO到TransportSmsSendLog转换失败", e);
        }
    }
}